@extends('layouts.home')

@section('content')
    @if(count($errors) > 0)
        <blockquote class="layui-elem-quote layui-bg-red">
                @foreach($errors->all() as $error)
                    {{ $error }} &nbsp;&nbsp;
                @endforeach
        </blockquote>
    @endif
    @if(Session::has('success'))
        <blockquote class="layui-elem-quote layui-bg-blue">
                {{ Session::get('success') }}
        </blockquote>
    @endif
    <div class="layui-card">
        <div class="layui-card-header">我的网站</div>
        <div class="layui-card-body">
            <table class="layui-hide" id="demo" lay-filter="demo"></table>
            <script type="text/html" id="name">
                @{{#  if(d.state === 1){ }}
                    <a href="{{ url('siteinfo-') }}@{{ d.id }}.html" class="layui-table-link" target="_blank">
                        @{{ d.name }}
                    </a>
                @{{#  } else { }}
                    @{{ d.name }}
                @{{#  } }}
            </script>
            <script type="text/html" id="state">
                @{{#  if(d.state === 1){ }}
                    <span style="color: #F581B1;">已审核</span>
                @{{#  } else { }}
                    审核中
                @{{#  } }}
            </script>
            <script type="text/html" id="barDemo">
                {{--<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>--}}
            </script>
        </div>
    </div>
@endsection

@section('scriptsAfterJs')
    <script>
        layui.use('table', function(){
            var table = layui.table;

            //展示已知数据
            table.render({
                elem: '#demo'
                ,cols: [[ //标题栏
                    {field: 'id', title: 'ID', width: 80, sort: true}
                    ,{field: 'name', title: '网站名称', mixwidth: 200, templet: '#name'}
                    ,{field: 'column_id', title: '分类', width: 100}
                    ,{field: 'updated_at', title: '添加时间', width: 200}
                    ,{field: 'state', title: '状态', width: 80, templet: '#state'}
                    ,{fixed: 'right', title: '操作', width:200, align:'center', toolbar: '#barDemo'}
                ]]
                ,data: {!! $sites !!}
                //,skin: 'line' //表格风格
                ,even: true
                ,page: true //是否显示分页
                ,limits: [5, 7, 10]
                ,limit: 5 //每页默认显示的数量
            });
            //监听工具条
            table.on('tool(demo)', function(obj){
                var data = obj.data;
                if(obj.event === 'detail'){
                    layer.msg('ID：'+ data.id + ' 的查看操作');
                } else if(obj.event === 'del'){
                    layer.confirm('真的删除行么', function(index){
                        obj.del();
                        layer.close(index);
                    });
                } else if(obj.event === 'edit'){
                    location.href= "{{ url('website') }}/"+data.id+"/edit";
                }
            });
        });
    </script>
@endsection
